/*
 * Copyright (C) 2013 Timothy Woodford.  All rights reserved.
 */

package game;

import sengine.EnemyCharacter;
import sengine.Object2D;
import sengine.Sprite;

/**
 * A place that enemies come out of
 * @author timothy
 */
public class SpawnPoint extends Sprite {
    private long lastUpdate;
    private final long firstUpdate;
    public int interval;
    public SpawnPoint(int x, int y, int interval) {
        super(x, y, 50, 50);
        setPhysType(Object2D.PhysicsType.FIXED);
        this.interval = interval;
        firstUpdate = System.currentTimeMillis();
    }
    
    @Override
    public void update(long millis) {
        super.update(millis);
        long diff = System.currentTimeMillis() - firstUpdate;
        if(System.currentTimeMillis() - lastUpdate > interval*Math.pow(Math.E, -diff/100000)) {
            doSpawn();
            lastUpdate = System.currentTimeMillis();
        }
    }
    
    public void doSpawn() {
        EnemyCharacter echar = new EnemyCharacter((int) getX(), (int) (getY() + getHeight()));
        addSprite(echar);
    }
}
